package com.zmn.oms.dubbo.impl.normal.wechat;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.interfaces.normal.wechat.WeChatRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.zmn.business.interfaces.wechat.WechatQrScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;

/**
 * 类描述：
 *
 * @author wangxiaokun
 * @since 2021/12/01 15:52
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 1000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class WeChatRemoteServiceImpl implements WeChatRemoteService {

    @Autowired
    private WechatQrScanService wechatQrScanService;

    /**
     * 获取微信公众号
     * @param orderId
     * @param masterId
     * @return
     */
    @Override
    public ResponseDTO<String> getWeChatQrCode(@NotNull(message = "订单号不能为空") Long orderId, @NotNull(message = "工程师id不能为空") Integer masterId) {
        try {
            return ResponseDTO.success(wechatQrScanService.getWeChatQrCodeUrl(orderId, masterId));
        } catch (OmsBaseException e) {
            e.printStackTrace();
            log.error("工程师获取微信公众号二维码失败：{}", e);
            return ResponseDTO.fail(e.getCode(), e.getMessage());
        }
    }
}
